<template>
	<view class="result-box">
		<image class="result-icon" :src="icon" mode="aspectFit"></image>
		<view class="result-info">
			<text class="result-title">{{title}}</text>
			<text class="result-desc" v-if="!$u.test.isEmpty(desc)">{{desc}}</text>
		</view>
		<view class="submit-btn btn" @tap="buttonClick">{{btnTitle}}</view>
	</view>
</template>

<script setup>
	import { ref } from 'vue'
	import { useUserStore } from '@/stores'
	const userStore = useUserStore()
	//图标
	const icon = ref('')
	//标题
	const title = ref('')
	//描述
	const desc = ref('')
	//按钮文字
	const btnTitle = ref('')
	//认证提交：submit 认证失败：fail 密码重置成功：password
	const resultType = ref('submit')
	//接收上个页面传递的参数
	const props = defineProps()
	
	if (props.type == 'fail'){
		//认证失败
		icon.value = '/static/result_icon2.png'
		title.value = '认证签约失败'
		desc.value = userStore.user.authRemark
		btnTitle.value = '重新认证'
	}
	else if (props.type == 'password'){
		//密码找回成功
		icon.value = '/static/result_icon3.png'
		title.value = '成功找回'
		desc.value = ''
		btnTitle.value = '去登录'
	}
	else{
		//认证提交成功
		icon.value = '/static/result_icon1.png'
		title.value = '认证提交成功，等待审核'
		desc.value = ''
		btnTitle.value = '返回首页'
	}
	const buttonClick = ()=>{
		if(btnTitle.value == '返回首页'){
			uni.switchTab({
				url:'/pages/home/home'
			})
		}
		else if(btnTitle.value == '去登录'){
			uni.$auth.logout()
			uni.reLaunch({
				url:'/pages/login/login'
			})
		}
		else{
			//重新认证
			if(userStore.user.merType == '0' || userStore.user.merType == '2'){
				uni.navigateTo({
					url:'/pages/auth/enterprise-info/enterprise-info'
				})
			}
			else{
				uni.navigateTo({
					url:'/pages/auth/idcard-info/idcard-info'
				})
			}
		}
	}
</script>

<style lang="scss">
	.result-box{
		display: flex;
		flex-direction: column;
		align-items: center;
		padding: 100rpx 30rpx 30rpx;
		box-sizing: border-box;
		.result-icon{
			width: 220rpx;
			height: 220rpx;
		}
		.result-info{
			display: flex;
			flex-direction: column;
			align-items: center;
			justify-content: center;
			text-align: center;
			.result-title{
				color: $xh-title-color;
				font-size: 30rpx;
				font-weight: 500;
				margin-top: 90rpx;
			}
			.result-desc{
				color: $xh-subtitle-color;
				font-size: 28rpx;
				margin-top: 32rpx;
			}
		}
		
		.btn{
			margin-top: 138rpx;
			width: 100%;
		}
	}
</style>
